package com.leapp.sk.viewdelegate.classs

import android.text.TextUtils
import android.view.View
import android.widget.ListView
import com.example.mvp.delegate.BaseAppDelegate
import com.example.mvp.view.SKTopBar
import com.leapp.sk.R
import com.leapp.sk.bean.TransferTecherEntity
import com.example.inter.ItemClickInterface
import com.leapp.sk.ui.activity.AppMainTableActivity
import com.leapp.sk.ui.activity.classs.ClassManagerTransferActivity
import com.leapp.sk.ui.adapter.TransferTecherAdapter

/**
 * 班级管理权转让视图托管
 * @author  chaohaipeng  on 2018/8/1.
 */
class ClassManagerTransferDelegate : BaseAppDelegate(){
    private var mAdapter:TransferTecherAdapter?=null

    override fun initWidget() {
    }

    override fun initLayoutRes(): Int {
        return R.layout.activity_class_manager_transfer
    }

    /**
     * 初始化适配器
     */
 fun initAdapter(mlist: List<TransferTecherEntity>,itemClickInterface: ItemClickInterface){
        val lsitView = getView<ListView>(R.id.lv_agmt_lsit)
        initHead(lsitView)
        mAdapter = TransferTecherAdapter(getActivity(), mlist,itemClickInterface)
        lsitView.adapter=mAdapter
 }

    /**
     * 刷新适配器
     */
    fun notifyAdapter(){
        mAdapter?.notifyDataSetChanged()
    }


    /**
     * 初始化头部
     */
  private  fun initHead(lsitView:ListView){
        val tabView = View.inflate(getActivity<AppMainTableActivity>(), R.layout.layout_class_manager_transfer_head, null)
        lsitView.addHeaderView(tabView)

    }
    /**
     * 设置标题栏
     */
    fun setTitle(title:String?){
        if (!TextUtils.isEmpty(title)){
            val jtb_agmt= getView<SKTopBar>(R.id.jtb_agmt)
            jtb_agmt.setTitle(title)
        }
        setEvent()
    }

    /**
     * 设置设置事件
     */
    fun setEvent(){
        val jtb_agmt= getView<SKTopBar>(R.id.jtb_agmt)
        jtb_agmt?.setEventInterface(object : SKTopBar.EventInterface{
            override fun leftOnClick() {
                getActivity<ClassManagerTransferActivity>().finish()

            }
            override fun rightOnClick() {

            }

        })
    }
}